package org.example.util;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUtil {
    private static final int EOF = -1;
    private static final int BUFFER_SIZE = 1024 * 4;

    public static long copy(final InputStream input,
                            final OutputStream output) throws IOException {
        long count = 0;
        int n;
        byte[] buffer = new byte[BUFFER_SIZE];
        while (EOF != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }

        return count;
    }

    public static void closeIO(final Closeable closeable) {
        if(closeable != null){
            try {
                closeable.close();
            } catch (IOException ignored) {
            }
        }

    }
}
